/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hype;
import java.util.HashMap;

/**
 *
 * @author Luca
 */
public class Event {
    String name;
    boolean stochastic;
    String guard;
    ResetList reset;
    String rate;
    String flowReset = null;

    public Event(String name, String guard, ResetList reset) {
        this.name = name;
        this.guard = guard;
        this.reset = reset;
        this.stochastic = false;
        this.rate = "";
    }

    public Event(String name, String guard, ResetList reset, String rate) {
        this.name = name;
        this.guard = guard;
        this.reset = reset;
        this.rate = rate;
        this.stochastic = true;
    }
    
    public void setFlowReset(HashMap<String,Integer> varToState) {
        this.flowReset = "";
        for (String s : varToState.keySet())
            flowReset += (!flowReset.isEmpty() ? "; " : "") + s + " = " + varToState.get(s);
    }
    
    
    EventTransition getTransition(GuardResetPair p) {
        if (this.flowReset == null)
            throw new HypeException("Flow state reset not set for this event!");
        String g = p.guard + (!this.guard.isEmpty() ? " && ( " + this.guard + " )" : "");
        String r = p.reset;
        if (!r.isEmpty() && !flowReset.isEmpty())
            r += "; ";
        r += flowReset;
        String r1 = this.reset.toString();
        if (!r.isEmpty() && !r1.isEmpty())
            r += "; ";
        r += r1;
        EventTransition t;
        if (this.stochastic)
            t = new EventTransition(name,g,r,rate);
        else
            t = new EventTransition(name,g,r);
       return t;
    }
    
}
